package com.wootion.cims.module.map.service.impl;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wootion.cims.dao.*;
import com.wootion.cims.general.utils.IdcardValidatorUtil;
import com.wootion.cims.general.utils.NationalityEnum;
import com.wootion.cims.general.utils.RedisUtil;
import com.wootion.cims.module.communitypersonal.model.Person;
import com.wootion.cims.module.communityresidence.residencelist.model.Residence;
import com.wootion.cims.module.map.service.MapService;
import com.wootion.cims.module.systemsetting.community.model.SysCommunity;
import com.wootion.cims.module.systemsetting.dictionary.model.SysDictionary;
import com.wootion.cims.module.systemsetting.user.model.SysUserRole;
import com.wootion.cims.module.systemsetting.user.model.User;
import com.wootion.cims.response.ResponseResult;
import com.wootion.cims.response.ResultCode;
import com.wootion.cims.shiro.utils.ShiroUtils;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
@Service
public class MapServiceImpl extends ServiceImpl<UserDao, User> implements MapService {
    @Autowired
    RedisUtil redisUtil;

    @Autowired(required = false)
    PersonDao personDao;

    @Autowired(required = false)
    ResidenceDao residenceDao;

    @Resource
    private SysUserRoleDao sysUserRoleDao;
    @Resource
    private SysRoleDao sysRoleDao;
    @Resource
    private SysUserCommunityDao sysUserCommunityDao;
    @Resource
    private SysCommunityDao sysCommunityDao;
    @Resource
    private SysPlotDao sysPlotDao;
    @Resource
    private SysDictionaryDao sysDictionaryDao;

    @Override
    public ResponseResult statistics(JSONObject jsonObject2) {
        List<String> stringList = new ArrayList<>();

        List<String> stringList2 = new ArrayList<>();

        QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
        QueryWrapper<Residence>  queryWrapper1 = new QueryWrapper<>();
        boolean isElter = false;
        boolean commit = false;
        if (Optional.ofNullable(jsonObject2.getString("communityId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("communityId")) ){
            queryWrapper1.eq("community_id",jsonObject2.getString("communityId"));
            isElter =true;
        }

        if (Optional.ofNullable(jsonObject2.getString("plotId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("plotId"))){
            queryWrapper1.eq("plot_id",jsonObject2.getString("plotId"));
            isElter =true;
        }
        queryWrapper.eq("enabled",true);
        if (isElter){
            List<Residence> residences = residenceDao.selectList(queryWrapper1);
            List<String> list = new ArrayList<>();
            for (Residence residence :residences){
                list.add(residence.getId());
            }
            if (!residences.isEmpty()){
                queryWrapper.in("abode_id",list);
            }else {
                List<String> list1 = new ArrayList<>();
                list1.add("哈哈哈");
                queryWrapper.in("abode_id",list1);
            }

        }

        //权限筛选
        //获取当前登陆人的信息
        User user = (User) ShiroUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.eq(SysUserRole::getUserId,user.getId());
        SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
        String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
        if (!"street:admin".equals(roleKey)) {
            List<String> commnityIds = sysUserCommunityDao.commnityIds(user.getId());
            if (Objects.isNull(commnityIds) || commnityIds.size() <= 0) {
                return ResponseResult.builder().message("当前用户还没有任何社区权限").build();
            }
            List<SysCommunity> communities = sysCommunityDao.findByCommunity(commnityIds);
            List<String> ids = new ArrayList<>();
            for (SysCommunity community : communities) {
                ids.add(community.getId());
            }
            QueryWrapper<Residence> queryWrapper2 = new QueryWrapper<>();
            List<Residence> residences = new ArrayList<>();
            if (!commnityIds.isEmpty()) {
                queryWrapper2.in("community_id", commnityIds);
                queryWrapper2.eq("enabled", true);
                residences = residenceDao.selectList(queryWrapper2);
            }else{

            }
            for (Residence residence : residences){
                stringList.add(residence.getId());
                stringList2.add(residence.getId());
            }
        }

        //        地区和权限筛选
        if (stringList.size()>0) {
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().eq("abode_id",""));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id",""));
            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList));
//            personQueryWrapper.eq("place_id","");
        }else if ("street:admin".equals(roleKey)){
            queryWrapper.isNotNull("abode_id");
            queryWrapper.ne("abode_id","");
        }else{
            return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message("访问用户没有任何社区权限").build();
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.eq("abode_id","").or().eq("place_id",""));
//            personQueryWrapper.isNull("abode_id");
        }
        List<Person> people = personDao.selectList(queryWrapper);
        Integer Total = new Integer(0);
        Integer man = new Integer(0);
        Integer women = new Integer(0);
        Integer party = new Integer(0);
        Integer old = new Integer(0);
        Integer under = new Integer(0);
        Integer disability = new Integer(0);
        Integer care = new Integer(0);
        Integer tent = new Integer(0);
        Integer local = new Integer(0);
        Integer out = new Integer(0);
        Integer other = new Integer(0);



        List<String> list = new ArrayList<>();
        Map<String,Integer> map = new HashMap<>();
        JSONArray types = jsonObject2.getJSONArray("types");
        if (Optional.ofNullable(types).isPresent()){
            list = types.toJavaList(String.class);
            commit =true;
        }
        if (commit) {
            for (String str : list) {
                map.put(str, new Integer(0));
            }
        }
        for (Person person : people){
            if (!StringUtil.isNullOrEmpty(person.getOldman()) && person.getOldmanInset().equals("true")){
                old++;
            }
            if (person.getGender().equals("男")){
                man++;
            }else {
                women++;
            }
            if (!StringUtil.isNullOrEmpty(person.getPartMan()) && person.getPartInset().equals("true")){
                party++;
                JSONObject jsonObject = JSONObject.parseObject(person.getPartMan());
                String partyManCategory = jsonObject.getString("partyManCategory");
                Boolean b = false;
                if (commit) {
                    if (Optional.ofNullable(partyManCategory).isPresent()) {
                        for (String s : list) {
                            if (partyManCategory.equals(s)) {
                                b = true;
                                Integer integer = map.get(s);
                                integer++;
                                map.put(s, integer);
                            }
                        }
                    }else {
                        other++;
                        b = true;
                    }
                    if (!b) {
                        other++;
                    }
                }
            }
            if (!StringUtil.isNullOrEmpty(person.getUnderProtect()) && person.getUnderInset().equals("true")){
                under++;
            }
            if (!StringUtil.isNullOrEmpty(person.getDeformedMan()) && person.getDeforInset().equals("true")){
                disability++;
            }
            if (!StringUtil.isNullOrEmpty(person.getCareMan()) && person.getCareInset().equals("true")){
                care++;
            }
            if (!StringUtil.isNullOrEmpty(person.getTenant()) && person.getTentInset().equals("true")){
                tent++;
            }
            if (person.getInside1()){
                local++;
            }else {
                out++;
            }
            Total++;
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("Total",Total);
        jsonObject.put("man",man);
        jsonObject.put("women",women);
        jsonObject.put("party",party);
        jsonObject.put("old",old);
        jsonObject.put("under",under);
        jsonObject.put("disability",disability);
        jsonObject.put("care",care);
        jsonObject.put("tent",tent);
        jsonObject.put("local",local);
        jsonObject.put("out",out);
        for (String s :list){
            jsonObject.put(s,map.get(s));
        }
        jsonObject.put("other",other);
        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(jsonObject).build();
    }

    @Override
    public ResponseResult statisticsByType(JSONObject jsonObject2) {
        List<String> stringList = new ArrayList<>();

        List<String> stringList2 = new ArrayList<>();

        QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
        QueryWrapper<Residence>  queryWrapper1 = new QueryWrapper<>();
        boolean isElter = false;
        boolean commit = false;
        if (Optional.ofNullable(jsonObject2.getString("communityId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("communityId")) ){
            queryWrapper1.eq("community_id",jsonObject2.getString("communityId"));
            isElter =true;
        }

        if (Optional.ofNullable(jsonObject2.getString("plotId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("plotId"))){
            queryWrapper1.eq("plot_id",jsonObject2.getString("plotId"));
            isElter =true;
        }
        queryWrapper.eq("enabled",true);
        if (isElter){
            List<Residence> residences = residenceDao.selectList(queryWrapper1);
            List<String> list = new ArrayList<>();
            for (Residence residence :residences){
                list.add(residence.getId());
            }
            if (!residences.isEmpty()){
                queryWrapper.in("abode_id",list);
            }else {
                List<String> list1 = new ArrayList<>();
                list1.add("哈哈哈");
                queryWrapper.in("abode_id",list1);
            }

        }

        //权限筛选
        //获取当前登陆人的信息
        User user = (User) ShiroUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.eq(SysUserRole::getUserId,user.getId());
        SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
        String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
        if (!"street:admin".equals(roleKey)) {
            List<String> commnityIds = sysUserCommunityDao.commnityIds(user.getId());
            if (Objects.isNull(commnityIds) || commnityIds.size() <= 0) {
                return ResponseResult.builder().message("当前用户还没有任何社区权限").build();
            }
            List<SysCommunity> communities = sysCommunityDao.findByCommunity(commnityIds);
            List<String> ids = new ArrayList<>();
            for (SysCommunity community : communities) {
                ids.add(community.getId());
            }
            QueryWrapper<Residence> queryWrapper2 = new QueryWrapper<>();
            List<Residence> residences = new ArrayList<>();
            if (!commnityIds.isEmpty()) {
                queryWrapper2.in("community_id", commnityIds);
                queryWrapper2.eq("enabled", true);
                residences = residenceDao.selectList(queryWrapper2);
            }else{

            }
            for (Residence residence : residences){
                stringList.add(residence.getId());
                stringList2.add(residence.getId());
            }
        }

        //        地区和权限筛选
        if (stringList.size()>0) {
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().eq("abode_id",""));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id",""));
            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList));
//            personQueryWrapper.eq("place_id","");
        }else if ("street:admin".equals(roleKey)){
             queryWrapper.isNotNull("abode_id");
            queryWrapper.ne("abode_id","");
        }else{
            return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message("访问用户没有任何社区权限").build();
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.eq("abode_id","").or().eq("place_id",""));
//            personQueryWrapper.isNull("abode_id");
        }
        List<Person> people = personDao.selectList(queryWrapper);

//        queryWrapper.eq(jsonObject2.getString("type"),true);
//        List<Person> people1 = personDao.selectList(queryWrapper);
//
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("s",people1.size());
//        jsonObject.put("all",people.size());
        Integer s0_18 = 0; //儿童总数
        Integer s0_1 = 0; //婴儿
        Integer s1_3 = 0; //幼儿
        Integer s3_6 = 0; //学龄前
        Integer s6_12 = 0; //学龄期
        Integer s12_18 = 0; //青春期

        List<Person> list = new ArrayList<>();
        for (Person person : people){
            try {
                if (Integer.valueOf(person.getAge()) <= 18) {
                    list.add(person);
                }
            }catch (Exception e ){
                list.add(person);
            }
        }
        s0_18 = list.size();

        for (Person person : list){
            if (person.getName().equals("张月庆")){
                System.out.println(1);
            }
            Integer integer = 0;
            try {
              integer  = Integer.valueOf(person.getAge());
            }catch (Exception e){
                s0_1++;
            }
             if (integer >=1 && integer<3){
                s1_3++;
            }
            else if (integer >=3 && integer<6){
                s3_6++;
            }
             else if (integer >=6 && integer<12){
                s6_12++;
            }
             else if (integer >=12 && integer<=18){
                s12_18++;
            }
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("s0_18",s0_18);
        jsonObject.put("s0_1",s0_1);
        jsonObject.put("s1_3",s1_3);
        jsonObject.put("s3_6",s3_6);
        jsonObject.put("s6_12",s6_12);
        jsonObject.put("s12_18",s12_18);

        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(jsonObject).build();
    }

    @Override
    public ResponseResult statisticsMap(JSONObject jsonObject2) {
        List<String> stringList = new ArrayList<>();

        List<String> stringList2 = new ArrayList<>();

        QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
        QueryWrapper<Residence>  queryWrapper1 = new QueryWrapper<>();
        boolean isElter = false;
        boolean commit = false;
        if (Optional.ofNullable(jsonObject2.getString("communityId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("communityId")) ){
            queryWrapper1.eq("community_id",jsonObject2.getString("communityId"));
            isElter =true;
        }

        if (Optional.ofNullable(jsonObject2.getString("plotId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("plotId"))){
            queryWrapper1.eq("plot_id",jsonObject2.getString("plotId"));
            isElter =true;
        }
        queryWrapper.eq("enabled",true);
        if (isElter){
            List<Residence> residences = residenceDao.selectList(queryWrapper1);
            List<String> list = new ArrayList<>();
            for (Residence residence :residences){
                list.add(residence.getId());
            }
            if (!residences.isEmpty()){
                queryWrapper.in("abode_id",list);
            }else {
                List<String> list1 = new ArrayList<>();
                list1.add("哈哈哈");
                queryWrapper.in("abode_id",list1);
            }

        }

        //权限筛选
        //获取当前登陆人的信息
        User user = (User) ShiroUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.eq(SysUserRole::getUserId,user.getId());
        SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
        String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
        if (!"street:admin".equals(roleKey)) {
            List<String> commnityIds = sysUserCommunityDao.commnityIds(user.getId());
            if (Objects.isNull(commnityIds) || commnityIds.size() <= 0) {
                return ResponseResult.builder().message("当前用户还没有任何社区权限").build();
            }
            List<SysCommunity> communities = sysCommunityDao.findByCommunity(commnityIds);
            List<String> ids = new ArrayList<>();
            for (SysCommunity community : communities) {
                ids.add(community.getId());
            }
            QueryWrapper<Residence> queryWrapper2 = new QueryWrapper<>();
            List<Residence> residences = new ArrayList<>();
            if (!commnityIds.isEmpty()) {
                queryWrapper2.in("community_id", commnityIds);
                queryWrapper2.eq("enabled", true);
                residences = residenceDao.selectList(queryWrapper2);
            }else{

            }
            for (Residence residence : residences){
                stringList.add(residence.getId());
                stringList2.add(residence.getId());
            }
        }

        //        地区和权限筛选
        if (stringList.size()>0) {
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().eq("abode_id",""));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id",""));
            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList));
//            personQueryWrapper.eq("place_id","");
        }else if ("street:admin".equals(roleKey)){
            queryWrapper.isNotNull("abode_id");
            queryWrapper.ne("abode_id","");
        }else{
            return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message("访问用户没有任何社区权限").build();
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.eq("abode_id","").or().eq("place_id",""));
//            personQueryWrapper.isNull("abode_id");
        }
        List<Person> people = personDao.selectList(queryWrapper);

//        queryWrapper.eq(jsonObject2.getString("type"),true);
//        List<Person> people1 = personDao.selectList(queryWrapper);
//
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("s",people1.size());
//        jsonObject.put("all",people.size());

        Integer sdate = jsonObject2.getInteger("sdate");
        Integer edate = jsonObject2.getInteger("edate");
        Date date = new Date();
//        int year = date.getYear();
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int i = sdate - year;

        List<JSONObject> jsonObjects = new ArrayList<>();

        List<Person> list = new ArrayList<>();
        for (Person person : people){
            try {
                if (Integer.valueOf(person.getAge()) <= 18) {
                    list.add(person);
                }
            }catch (Exception e ){
                list.add(person);
            }
        }

        for (Person person : list){
            Integer integer = 0;
            try {
                integer  = Integer.valueOf(person.getAge());
            }catch (Exception e){
                if (integer!=0) {
                    person.setAge(String.valueOf(i));
                }
                continue;
            }
            person.setAge(String.valueOf(Integer.valueOf(person.getAge())+i));
        }

        for (int j = sdate; j <= edate; j++) {

//            Integer s0_18 = 0; //儿童总数
            Integer s0_1 = 0; //婴儿
            Integer s1_3 = 0; //幼儿
            Integer s3_6 = 0; //学龄前
            Integer s6_12 = 0; //学龄期
            Integer s12_18 = 0; //青春期

            for (Person person : list){
                Integer integer = 0;
                try {
                    integer  = Integer.valueOf(person.getAge());
                }catch (Exception e){
                    s0_1++;
                    person.setAge(String.valueOf(1));
                }
                if (integer >=1 && integer<3){
                    s1_3++;
                }else
                if (integer >=3 && integer<6){
                    s3_6++;
                }else
                if (integer >=6 && integer<12){
                    s6_12++;
                }else
                if (integer >=12 && integer<=18){
                    s12_18++;
                }
                person.setAge(String.valueOf(Integer.valueOf(person.getAge())+1));
            }

            JSONObject jsonObject = new JSONObject();
//            jsonObject.put("s0_18",s0_18);
            jsonObject.put("s0_1",s0_1);
            jsonObject.put("s1_3",s1_3);
            jsonObject.put("s3_6",s3_6);
            jsonObject.put("s6_12",s6_12);
            jsonObject.put("s12_18",s12_18);

            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put(String.valueOf(j),jsonObject);
            jsonObjects.add(jsonObject1);
        }


        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(jsonObjects).build();
    }

    @Override
    public ResponseResult statisticsMapCircle(JSONObject jsonObject2) {
        List<String> stringList = new ArrayList<>();

        List<String> stringList2 = new ArrayList<>();

        QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
        QueryWrapper<Residence>  queryWrapper1 = new QueryWrapper<>();
        boolean isElter = false;
        boolean commit = false;
        if (Optional.ofNullable(jsonObject2.getString("communityId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("communityId")) ){
            queryWrapper1.eq("community_id",jsonObject2.getString("communityId"));
            isElter =true;
        }

        if (Optional.ofNullable(jsonObject2.getString("plotId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("plotId"))){
            queryWrapper1.eq("plot_id",jsonObject2.getString("plotId"));
            isElter =true;
        }
        queryWrapper.eq("enabled",true);
        if (isElter){
            List<Residence> residences = residenceDao.selectList(queryWrapper1);
            List<String> list = new ArrayList<>();
            for (Residence residence :residences){
                list.add(residence.getId());
            }
            if (!residences.isEmpty()){
                queryWrapper.in("abode_id",list);
            }else {
                List<String> list1 = new ArrayList<>();
                list1.add("哈哈哈");
                queryWrapper.in("abode_id",list1);
            }

        }

        //权限筛选
        //获取当前登陆人的信息
        User user = (User) ShiroUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.eq(SysUserRole::getUserId,user.getId());
        SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
        String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
        if (!"street:admin".equals(roleKey)) {
            List<String> commnityIds = sysUserCommunityDao.commnityIds(user.getId());
            if (Objects.isNull(commnityIds) || commnityIds.size() <= 0) {
                return ResponseResult.builder().message("当前用户还没有任何社区权限").build();
            }
            List<SysCommunity> communities = sysCommunityDao.findByCommunity(commnityIds);
            List<String> ids = new ArrayList<>();
            for (SysCommunity community : communities) {
                ids.add(community.getId());
            }
            QueryWrapper<Residence> queryWrapper2 = new QueryWrapper<>();
            List<Residence> residences = new ArrayList<>();
            if (!commnityIds.isEmpty()) {
                queryWrapper2.in("community_id", commnityIds);
                queryWrapper2.eq("enabled", true);
                residences = residenceDao.selectList(queryWrapper2);
            }else{

            }
            for (Residence residence : residences){
                stringList.add(residence.getId());
                stringList2.add(residence.getId());
            }
        }

        //        地区和权限筛选
        if (stringList.size()>0) {
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().eq("abode_id",""));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id",""));
            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList));
//            personQueryWrapper.eq("place_id","");
        }else if ("street:admin".equals(roleKey)){
             queryWrapper.isNotNull("abode_id");
            queryWrapper.ne("abode_id","");
        }else{
            return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message("访问用户没有任何社区权限").build();
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.eq("abode_id","").or().eq("place_id",""));
//            personQueryWrapper.isNull("abode_id");
        }
        List<Person> people = personDao.selectList(queryWrapper);

        int a = jsonObject2.getInteger("type");
        int man = 0;
        int woman = 0;
        List<Person> list = new ArrayList<>();
        for (Person person : people){
            Integer integer =0;
            try {
                integer = Integer.valueOf(person.getAge());
            }catch (Exception e ){
                if (a ==0) {
                    list.add(person);
                    continue;
                }
                if (a == 5){
                    list.add(person);
                    continue;
                }
            }
            switch (a){
                case 1:{
                    if (integer >=1 && integer<3){
                        list.add(person);
                    }
                    continue;
                }
                case 2:{
                    if (integer >=3 && integer<6){
                        list.add(person);
                    }
                    continue;
                }
                case 3 :{
                    if (integer >=6 && integer<12){
                        list.add(person);
                    }
                    continue;

                }
                case 4 :{
                    if (integer >=12 && integer<18){
                        list.add(person);
                    }
                    continue;
                }
                case 5 :{
                    if (integer<=18){
                        list.add(person);
                    }
                    continue;
                }
            }
        }

        for (Person person : list){
            if (person.getGender().equals("男")){
                man++;
            }else {
                woman++;
            }
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("man",man);
        jsonObject.put("woman",woman);
        jsonObject.put("type",a);

        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(jsonObject).build();
    }

    @Override
    public ResponseResult statisticsByTypeOld(JSONObject jsonObject2) {
        List<String> stringList = new ArrayList<>();

        List<String> stringList2 = new ArrayList<>();

        QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
        QueryWrapper<Residence>  queryWrapper1 = new QueryWrapper<>();
        boolean isElter = false;
        boolean commit = false;
        if (Optional.ofNullable(jsonObject2.getString("communityId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("communityId")) ){
            queryWrapper1.eq("community_id",jsonObject2.getString("communityId"));
            isElter =true;
        }

        if (Optional.ofNullable(jsonObject2.getString("plotId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("plotId"))){
            queryWrapper1.eq("plot_id",jsonObject2.getString("plotId"));
            isElter =true;
        }
        queryWrapper.eq("enabled",true);
        if (isElter){
            List<Residence> residences = residenceDao.selectList(queryWrapper1);
            List<String> list = new ArrayList<>();
            for (Residence residence :residences){
                list.add(residence.getId());
            }
            if (!residences.isEmpty()){
                queryWrapper.in("abode_id",list);
            }else {
                List<String> list1 = new ArrayList<>();
                list1.add("哈哈哈");
                queryWrapper.in("abode_id",list1);
            }

        }

        //权限筛选
        //获取当前登陆人的信息
        User user = (User) ShiroUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.eq(SysUserRole::getUserId,user.getId());
        SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
        String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
        if (!"street:admin".equals(roleKey)) {
            List<String> commnityIds = sysUserCommunityDao.commnityIds(user.getId());
            if (Objects.isNull(commnityIds) || commnityIds.size() <= 0) {
                return ResponseResult.builder().message("当前用户还没有任何社区权限").build();
            }
            List<SysCommunity> communities = sysCommunityDao.findByCommunity(commnityIds);
            List<String> ids = new ArrayList<>();
            for (SysCommunity community : communities) {
                ids.add(community.getId());
            }
            QueryWrapper<Residence> queryWrapper2 = new QueryWrapper<>();
            List<Residence> residences = new ArrayList<>();
            if (!commnityIds.isEmpty()) {
                queryWrapper2.in("community_id", commnityIds);
                queryWrapper2.eq("enabled", true);
                residences = residenceDao.selectList(queryWrapper2);
            }else{

            }
            for (Residence residence : residences){
                stringList.add(residence.getId());
                stringList2.add(residence.getId());
            }
        }

        //        地区和权限筛选
        if (stringList.size()>0) {
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().eq("abode_id",""));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id",""));
            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList));
//            personQueryWrapper.eq("place_id","");
        }else if ("street:admin".equals(roleKey)){
            queryWrapper.isNotNull("abode_id");
            queryWrapper.ne("abode_id","");
        }else{
            return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message("访问用户没有任何社区权限").build();
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.eq("abode_id","").or().eq("place_id",""));
//            personQueryWrapper.isNull("abode_id");
        }
        List<Person> people = personDao.selectList(queryWrapper);

//        queryWrapper.eq(jsonObject2.getString("type"),true);
//        List<Person> people1 = personDao.selectList(queryWrapper);
//
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("s",people1.size());
//        jsonObject.put("all",people.size());
        Integer s60_ = 0; //总数
        Integer s60_70 = 0;
        Integer s70_80 = 0;
        Integer s80_90 = 0;
        Integer s90_ = 0;

        List<Person> list = new ArrayList<>();
        for (Person person : people){
            try {
                if (Integer.valueOf(person.getAge()) >= 60) {
                    list.add(person);
                }
            }catch (Exception e ){
            }
        }
        s60_ = list.size();

        for (Person person : list){
            Integer integer = 0;
            try {
                integer  = Integer.valueOf(person.getAge());
            }catch (Exception e){
            }
            if (integer >=60 && integer<70){
                s60_70++;
            }
            if (integer >=70 && integer<80){
                s70_80++;
            }
            if (integer >=80 && integer<90){
                s80_90++;
            }
            if (integer >=90 ){
                s90_++;
            }
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("s60_",s60_);
        jsonObject.put("s60_70",s60_70);
        jsonObject.put("s70_80",s70_80);
        jsonObject.put("s80_90",s80_90);
        jsonObject.put("s90_",s90_);

        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(jsonObject).build();
    }

    @Override
    public ResponseResult statisticsMapOld(JSONObject jsonObject2) {
        List<String> stringList = new ArrayList<>();

        List<String> stringList2 = new ArrayList<>();

        QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
        QueryWrapper<Residence>  queryWrapper1 = new QueryWrapper<>();
        boolean isElter = false;
        boolean commit = false;
        if (Optional.ofNullable(jsonObject2.getString("communityId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("communityId")) ){
            queryWrapper1.eq("community_id",jsonObject2.getString("communityId"));
            isElter =true;
        }

        if (Optional.ofNullable(jsonObject2.getString("plotId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("plotId"))){
            queryWrapper1.eq("plot_id",jsonObject2.getString("plotId"));
            isElter =true;
        }
        queryWrapper.eq("enabled",true);
        if (isElter){
            List<Residence> residences = residenceDao.selectList(queryWrapper1);
            List<String> list = new ArrayList<>();
            for (Residence residence :residences){
                list.add(residence.getId());
            }
            if (!residences.isEmpty()){
                queryWrapper.in("abode_id",list);
            }else {
                List<String> list1 = new ArrayList<>();
                list1.add("哈哈哈");
                queryWrapper.in("abode_id",list1);
            }

        }

        //权限筛选
        //获取当前登陆人的信息
        User user = (User) ShiroUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.eq(SysUserRole::getUserId,user.getId());
        SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
        String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
        if (!"street:admin".equals(roleKey)) {
            List<String> commnityIds = sysUserCommunityDao.commnityIds(user.getId());
            if (Objects.isNull(commnityIds) || commnityIds.size() <= 0) {
                return ResponseResult.builder().message("当前用户还没有任何社区权限").build();
            }
            List<SysCommunity> communities = sysCommunityDao.findByCommunity(commnityIds);
            List<String> ids = new ArrayList<>();
            for (SysCommunity community : communities) {
                ids.add(community.getId());
            }
            QueryWrapper<Residence> queryWrapper2 = new QueryWrapper<>();
            List<Residence> residences = new ArrayList<>();
            if (!commnityIds.isEmpty()) {
                queryWrapper2.in("community_id", commnityIds);
                queryWrapper2.eq("enabled", true);
                residences = residenceDao.selectList(queryWrapper2);
            }else{

            }
            for (Residence residence : residences){
                stringList.add(residence.getId());
                stringList2.add(residence.getId());
            }
        }

        //        地区和权限筛选
        if (stringList.size()>0) {
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().eq("abode_id",""));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id",""));
            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList));
//            personQueryWrapper.eq("place_id","");
        }else if ("street:admin".equals(roleKey)){
             queryWrapper.isNotNull("abode_id");
            queryWrapper.ne("abode_id","");
        }else{
            return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message("访问用户没有任何社区权限").build();
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.eq("abode_id","").or().eq("place_id",""));
//            personQueryWrapper.isNull("abode_id");
        }
        List<Person> people = personDao.selectList(queryWrapper);

//        queryWrapper.eq(jsonObject2.getString("type"),true);
//        List<Person> people1 = personDao.selectList(queryWrapper);
//
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("s",people1.size());
//        jsonObject.put("all",people.size());

        Integer sdate = jsonObject2.getInteger("sdate");
        Integer edate = jsonObject2.getInteger("edate");
        Date date = new Date();
//        int year = date.getYear();
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int i = sdate - year;

        List<JSONObject> jsonObjects = new ArrayList<>();

        List<Person> list = new ArrayList<>();
        for (Person person : people){
            try {
                if (Integer.valueOf(person.getAge()) >= 60) {
                    list.add(person);
                }
            }catch (Exception e ){
            }
        }

        for (Person person : list){
            Integer integer = 0;
            try {
                integer  = Integer.valueOf(person.getAge());
            }catch (Exception e){
                person.setAge(String.valueOf(i));
            }
            person.setAge(String.valueOf(Integer.valueOf(person.getAge())+i));
        }

        for (int j = sdate; j <= edate; j++) {

            Integer s60_ = 0; //总数
            Integer s60_70 = 0;
            Integer s70_80 = 0;
            Integer s80_90 = 0;
            Integer s90_ = 0;
            for (Person person : list){
                Integer integer = 0;
                try {
                    integer  = Integer.valueOf(person.getAge());
                }catch (Exception e){
                    person.setAge(String.valueOf(1));
                }
                if (integer >=60 && integer<70){
                    s60_70++;
                }
                if (integer >=70 && integer<80){
                    s70_80++;
                }
                if (integer >=80 && integer<90){
                    s80_90++;
                }
                if (integer >=90 ){
                    s90_++;
                }
                person.setAge(String.valueOf(Integer.valueOf(person.getAge())+1));
            }

            JSONObject jsonObject = new JSONObject();
            jsonObject.put("s60_",s60_);
            jsonObject.put("s60_70",s60_70);
            jsonObject.put("s70_80",s70_80);
            jsonObject.put("s80_90",s80_90);
            jsonObject.put("s90_",s90_);

            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put(String.valueOf(j),jsonObject);
            jsonObjects.add(jsonObject1);
        }


        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(jsonObjects).build();
    }

    @Override
    public ResponseResult statisticsMapCircleOld(JSONObject jsonObject2) {
        List<String> stringList = new ArrayList<>();

        List<String> stringList2 = new ArrayList<>();

        QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
        QueryWrapper<Residence>  queryWrapper1 = new QueryWrapper<>();
        boolean isElter = false;
        boolean commit = false;
        if (Optional.ofNullable(jsonObject2.getString("communityId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("communityId")) ){
            queryWrapper1.eq("community_id",jsonObject2.getString("communityId"));
            isElter =true;
        }

        if (Optional.ofNullable(jsonObject2.getString("plotId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("plotId"))){
            queryWrapper1.eq("plot_id",jsonObject2.getString("plotId"));
            isElter =true;
        }
        queryWrapper.eq("enabled",true);
        if (isElter){
            List<Residence> residences = residenceDao.selectList(queryWrapper1);
            List<String> list = new ArrayList<>();
            for (Residence residence :residences){
                list.add(residence.getId());
            }
            if (!residences.isEmpty()){
                queryWrapper.in("abode_id",list);
            }else {
                List<String> list1 = new ArrayList<>();
                list1.add("哈哈哈");
                queryWrapper.in("abode_id",list1);
            }

        }

        //权限筛选
        //获取当前登陆人的信息
        User user = (User) ShiroUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.eq(SysUserRole::getUserId,user.getId());
        SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
        String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
        if (!"street:admin".equals(roleKey)) {
            List<String> commnityIds = sysUserCommunityDao.commnityIds(user.getId());
            if (Objects.isNull(commnityIds) || commnityIds.size() <= 0) {
                return ResponseResult.builder().message("当前用户还没有任何社区权限").build();
            }
            List<SysCommunity> communities = sysCommunityDao.findByCommunity(commnityIds);
            List<String> ids = new ArrayList<>();
            for (SysCommunity community : communities) {
                ids.add(community.getId());
            }
            QueryWrapper<Residence> queryWrapper2 = new QueryWrapper<>();
            List<Residence> residences = new ArrayList<>();
            if (!commnityIds.isEmpty()) {
                queryWrapper2.in("community_id", commnityIds);
                queryWrapper2.eq("enabled", true);
                residences = residenceDao.selectList(queryWrapper2);
            }else{

            }
            for (Residence residence : residences){
                stringList.add(residence.getId());
                stringList2.add(residence.getId());
            }
        }

        //        地区和权限筛选
        if (stringList.size()>0) {
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().eq("abode_id",""));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id",""));
            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList));
//            personQueryWrapper.eq("place_id","");
        }else if ("street:admin".equals(roleKey)){
             queryWrapper.isNotNull("abode_id");
            queryWrapper.ne("abode_id","");
        }else{
            return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message("访问用户没有任何社区权限").build();
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.eq("abode_id","").or().eq("place_id",""));
//            personQueryWrapper.isNull("abode_id");
        }
        List<Person> people = personDao.selectList(queryWrapper);

        int a = jsonObject2.getInteger("type");
        int man = 0;
        int woman = 0;
        List<Person> list = new ArrayList<>();
        for (Person person : people){
            Integer integer =0;
            try {
                integer = Integer.valueOf(person.getAge());
            }catch (Exception e ){
            }
            switch (a){
                case 1:{
                    if (integer >=60 && integer<70){
                        list.add(person);
                    }
                    continue;
                }
                case 2:{
                    if (integer >=70 && integer<80){
                        list.add(person);
                    }
                    continue;
                }
                case 3 :{
                    if (integer >=80 && integer<90){
                        list.add(person);
                    }
                    continue;

                }
                case 4 :{
                    if (integer >=90 ){
                        list.add(person);
                    }
                    continue;
                }
                case 5 :{
                    if (integer>=60){
                        list.add(person);
                    }
                    continue;
                }
            }
        }

        for (Person person : list){
            if (person.getGender().equals("男")){
                man++;
            }else {
                woman++;
            }
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("man",man);
        jsonObject.put("woman",woman);
        jsonObject.put("type",a);

        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(jsonObject).build();
    }

    @Override
    public ResponseResult statisticsOld(JSONObject jsonObject2) {
        List<String> stringList = new ArrayList<>();

        List<String> stringList2 = new ArrayList<>();

        QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
        QueryWrapper<Residence>  queryWrapper1 = new QueryWrapper<>();
        boolean isElter = false;
        boolean commit = false;
        if (Optional.ofNullable(jsonObject2.getString("communityId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("communityId")) ){
            queryWrapper1.eq("community_id",jsonObject2.getString("communityId"));
            isElter =true;
        }

        if (Optional.ofNullable(jsonObject2.getString("plotId")).isPresent() && !StringUtil.isNullOrEmpty(jsonObject2.getString("plotId"))){
            queryWrapper1.eq("plot_id",jsonObject2.getString("plotId"));
            isElter =true;
        }
        queryWrapper.eq("enabled",true);
        if (isElter){
            List<Residence> residences = residenceDao.selectList(queryWrapper1);
            List<String> list = new ArrayList<>();
            for (Residence residence :residences){
                list.add(residence.getId());
            }
            if (!residences.isEmpty()){
                queryWrapper.in("abode_id",list);
            }else {
                List<String> list1 = new ArrayList<>();
                list1.add("哈哈哈");
                queryWrapper.in("abode_id",list1);
            }

        }

        //权限筛选
        //获取当前登陆人的信息
        User user = (User) ShiroUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.eq(SysUserRole::getUserId,user.getId());
        SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
        String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
        if (!"street:admin".equals(roleKey)) {
            List<String> commnityIds = sysUserCommunityDao.commnityIds(user.getId());
            if (Objects.isNull(commnityIds) || commnityIds.size() <= 0) {
                return ResponseResult.builder().message("当前用户还没有任何社区权限").build();
            }
            List<SysCommunity> communities = sysCommunityDao.findByCommunity(commnityIds);
            List<String> ids = new ArrayList<>();
            for (SysCommunity community : communities) {
                ids.add(community.getId());
            }
            QueryWrapper<Residence> queryWrapper2 = new QueryWrapper<>();
            List<Residence> residences = new ArrayList<>();
            if (!commnityIds.isEmpty()) {
                queryWrapper2.in("community_id", commnityIds);
                queryWrapper2.eq("enabled", true);
                residences = residenceDao.selectList(queryWrapper2);
            }else{

            }
            for (Residence residence : residences){
                stringList.add(residence.getId());
                stringList2.add(residence.getId());
            }
        }

        //        地区和权限筛选
        if (stringList.size()>0) {
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().eq("abode_id",""));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id",""));
            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList));
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList));
//            personQueryWrapper.eq("place_id","");
        }else if ("street:admin".equals(roleKey)){
             queryWrapper.isNotNull("abode_id");
            queryWrapper.ne("abode_id","");
        }else{
            return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message("访问用户没有任何社区权限").build();
//            queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.eq("abode_id","").or().eq("place_id",""));
//            personQueryWrapper.isNull("abode_id");
        }

        queryWrapper.eq("oldman_inset","true");
        List<Person> people = personDao.selectList(queryWrapper);

        Map<String,Integer> survivalSkillsm = new HashMap<>();
        Map<String,Integer> economicSourcem = new HashMap<>();
        Map<String,Integer> effectm = new HashMap<>();
        Map<String,Integer> spousem = new HashMap<>();

        QueryWrapper<SysDictionary> sysDictionaryQueryWrapper = new QueryWrapper<>();
        sysDictionaryQueryWrapper.eq("type","老年人信息");
        sysDictionaryQueryWrapper.eq("name","经济来源");
        sysDictionaryQueryWrapper.eq("enabled",1);
        SysDictionary sysDictionary = sysDictionaryDao.selectOne(sysDictionaryQueryWrapper);
        if (Optional.ofNullable(sysDictionary).isPresent()) {
            String value = sysDictionary.getValue();
            String[] split = value.split(",");
            for (String s : split) {
                if (!economicSourcem.containsKey(s)) {
                    economicSourcem.put(s, 0);
                }
            }
        }

        QueryWrapper<SysDictionary> sysDictionaryQueryWrapper2 = new QueryWrapper<>();
        sysDictionaryQueryWrapper2.eq("type","老年人信息");
        sysDictionaryQueryWrapper2.eq("name","生活能力");
        sysDictionaryQueryWrapper2.eq("enabled",1);
        SysDictionary sysDictionary2 = sysDictionaryDao.selectOne(sysDictionaryQueryWrapper2);
        if (Optional.ofNullable(sysDictionary2).isPresent()) {
            String value2 = sysDictionary2.getValue();
            String[] split2 = value2.split(",");
            for (String s : split2) {
                if (!survivalSkillsm.containsKey(s)) {
                    survivalSkillsm.put(s, 0);
                }
            }
        }

        QueryWrapper<SysDictionary> sysDictionaryQueryWrapper3 = new QueryWrapper<>();
        sysDictionaryQueryWrapper3.eq("type","老年人信息");
        sysDictionaryQueryWrapper3.eq("name","发挥作用");
        sysDictionaryQueryWrapper3.eq("enabled",1);
        SysDictionary sysDictionary3 = sysDictionaryDao.selectOne(sysDictionaryQueryWrapper3);

        if (Optional.ofNullable(sysDictionary3).isPresent()) {
            String value3 = sysDictionary3.getValue();
            String[] split3 = value3.split(",");
            for (String s : split3) {
                if (!effectm.containsKey(s)) {
                    effectm.put(s, 0);
                }
            }
        }

        QueryWrapper<SysDictionary> sysDictionaryQueryWrapper4 = new QueryWrapper<>();
        sysDictionaryQueryWrapper4.eq("type","老年人信息");
        sysDictionaryQueryWrapper4.eq("name","配偶情况");
        sysDictionaryQueryWrapper4.eq("enabled",1);
        SysDictionary sysDictionary4 = sysDictionaryDao.selectOne(sysDictionaryQueryWrapper4);
        if (Optional.ofNullable(sysDictionary4).isPresent()) {
            String value4 = sysDictionary4.getValue();
            String[] split4 = value4.split(",");
            for (String s : split4) {
                if (!spousem.containsKey(s)) {
                    spousem.put(s, 0);
                }
            }
        }

        for (Person person : people){
            if (person.getIdNumber().equals("312019196302081531")){
                System.out.println("a");
            }
            String oldman = person.getOldman();
            JSONObject jsonObject = JSONObject.parseObject(oldman);

            String survivalSkills = jsonObject.getString("survivalSkills");
            if (!StringUtil.isNullOrEmpty(survivalSkills)){
                Integer integer = survivalSkillsm.get(survivalSkills);
                if (Optional.ofNullable(integer).isPresent()){
                    survivalSkillsm.put(survivalSkills,++integer);
                }else {
                    survivalSkillsm.put(survivalSkills,1);
                }
            }

            String economicSource = jsonObject.getString("economicSource");
            if (!StringUtil.isNullOrEmpty(economicSource)){
                Integer integer = economicSourcem.get(economicSource);
                if (Optional.ofNullable(integer).isPresent()){
                    economicSourcem.put(economicSource,++integer);
                }else {
                    economicSourcem.put(economicSource,1);
                }
            }

            String effect = jsonObject.getString("effect");
            if (!StringUtil.isNullOrEmpty(effect)){
                Integer integer = effectm.get(effect);
                if (Optional.ofNullable(integer).isPresent()){
                    effectm.put(effect,++integer);
                }else {
                    effectm.put(effect,1);
                }
            }

            String spouse = jsonObject.getString("spouse");
            if (!StringUtil.isNullOrEmpty(spouse)){
                Integer integer = spousem.get(spouse);
                if (Optional.ofNullable(integer).isPresent()){
                    spousem.put(spouse,++integer);
                }else {
                    spousem.put(spouse,1);
                }
            }
        }

        JSONObject jsonObject =new JSONObject();
        jsonObject.put("survivalSkillsm",survivalSkillsm);
        jsonObject.put("economicSourcem",economicSourcem);
        jsonObject.put("effectm",effectm);
        jsonObject.put("spousem",spousem);

        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(jsonObject).build();
    }


}
